<?php
class TbfError {
    //需要返回给客户端的错误,一定会中断当前的请求
    static function client($reason,$http_code=500){
        //后台的解决方案
        throw new \TbfError\ClientErrorException($reason,$http_code);
    }
    //没有预料到的错误(通常是编程逻辑错误),不应该显示给客户端
    static function unExpect($reason){
        throw new Exception($reason);
    }

    //设置客户端错误的处理回调, 预期行为应该是中断的处理过程(和抛异常类似)
    private static $clientErrorHandler = null;
    static function setClientErrorHandler( $handler ){
        self::$clientErrorHandler = $handler;
    }
    static function setClientErrorHandlerException(){
        self::$clientErrorHandler = function($reason){
            throw new TbfClientException($reason);
        };
    }
}